import { Stud } from "../Stud";
import { Usage } from "../StudUsage";
import { Cable } from "./Cable";
import { CableClass } from "./CableClass";

export default class CablePort {
    
    constructor(public cableClass: CableClass) {}

    public mapStuds: {[key: string]: Stud} = {}

    hasConnected() {
        for(let stud of Object.values(this.mapStuds)) {
            if(!stud.bus || !stud.bus.findHostStud())
                return false
        }
        return true
    }

    takeCable(cable:Cable) {
        for(let usage in this.mapStuds) {
            let stud = this.mapStuds[usage]
            if(!stud.bus)
                continue
            let provider = stud.bus.findHostStud()
            if(!provider)
                continue
            cable.setHostStud(usage as Usage, provider)
        }

    }
}